package com.wwj.my_ummary.util.threadpollutil;

import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author admin007
 * 线程
 */
@Configuration
public class ThreadPollUtil {

    private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();



    /**
     * 手动通过 ThreadPoolExecutor 创建线程池
     * <p>
     * corePoolSize用于指定核心线程数量
     * maximumPoolSize指定最大线程数
     * keepAliveTime和TimeUnit指定线程空闲后的最大存活时间
     * <p>
     * 可以根据项目的需要自定义线程池的参数
     */
    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(
            CORE_POOL_SIZE
            , CORE_POOL_SIZE + 10
            , 10L
            , TimeUnit.SECONDS
            , new LinkedBlockingQueue<Runnable>(1000));


}
